﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using GeoWeb.DataContext;

namespace GeoWeb.Demo.ButtonConfigInfo
{
    public class MenuTreeChildNodesDal : GeoWeb.Demo.DataContext.DbUtity
    {
        ButtonInfoDal ButtonDal = new ButtonInfoDal(); 
        /// <summary>
        /// 查询一条记录
        /// </summary>
        /// <param name="NodesGuid">菜单主键</param>
        /// <returns></returns>
        public GeoConfigTreeChildNodes select(string NodesGuid)
        {
            return Db.From<GeoConfigTreeChildNodes>().Where(GeoConfigTreeChildNodes._.NodesGuid == NodesGuid).ToSingle();
        }
        /// <summary>
        /// 添加一条记录
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public int AddEntity(GeoConfigTreeChildNodes entity)
        {
            return Db.Save<GeoConfigTreeChildNodes>(entity);
        }

        /// <summary>
        /// 修改一条记录
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public int UpdateEntity(GeoConfigTreeChildNodes entity, Field[] Field_Arry, object[] value_Arry, WhereClip Where)
        {
            entity.Attach();
            return Db.Update<GeoConfigTreeChildNodes>(Field_Arry, value_Arry, Where);
        }
        /// <summary>
        /// 获取页面按钮信息
        /// </summary>
        /// <param name="NodesGuid">当前页面主键</param>
        /// <returns></returns>
        public List<GeoButtonInfo> GetPageButton(string NodesGuid)
        {
            List<GeoButtonInfo> list = new List<GeoButtonInfo>();
            GeoConfigTreeChildNodes entity = select(NodesGuid);
            object[] o = null;
            if (entity != null && entity.ButtonInfo != "")
            {
                o = entity.ButtonInfo.Split('@');
            }
            if (o != null && o.Length > 0)
            {
               
                for (int i = 0; i < o.Length; i++)
                {
                    int id = 0;
                    int.TryParse(o[i].ToString(), out id);
                    
                    GeoButtonInfo btn = ButtonDal.GetButtonByID(id);
                    if (btn != null)
                    {
                        list.Add(btn);
                    }
                }
            }
            return list;
        }
    }
}